package 栈和队列;

import java.util.Stack;

public class LC_1047删除字符串中的所有相邻重复项 {
    public static void main(String[] args){
        String s="abbaca";
        System.out.println(removeDuplicates(s));
    }

    public static String removeDuplicates(String s) {
        int top=-1;//模拟栈
        char[] c=s.toCharArray();
        for(int i=0;i<c.length;i++){
            if(top==-1 || c[i]!=c[top]){
                top++;
                c[top]=c[i];
            }
            else
                top--;
        }
        return String.valueOf(c,0,top+1);
    }
}
